﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TuiXin
{
    public class cbc
    {
        public static byte[] cbc_rc4_Encrypt(byte[] bytes,byte[] key)
        {
            byte link = 0;
            byte[] rc4 = RC4Crypto.Encrypt(bytes, key);
            for (int i = 0; i < rc4.Length; ++i)
            {
                rc4[i] ^= link;
                link = rc4[i];
            }
            return rc4;
        }
        public static byte[] cbc_rc4_Decrypt(byte[] bytes,byte[] key)
        {
            byte link = 0;
            for (int i = 0; i < bytes.Length; ++i)
            {
                byte tmp = bytes[i];
                bytes[i] ^= link;
                link = tmp;
            }
            byte[] rc4 = RC4Crypto.Decrypt(bytes, key);

            return rc4;
        }
    }
}
